package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.business.dao.inter.ReceiptDao;
import com.yunfeisoft.business.model.Elder;
import com.yunfeisoft.business.model.Receipt;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * ClassName: ReceiptDaoImpl
 * Description: 收款单Dao实现
 * Author: Jackie liu
 * Date: 2020-04-01
 */
@Repository
public class ReceiptDaoImpl extends BaseDaoImpl<Receipt, String> implements ReceiptDao {

    @Override
    public Page<Receipt> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        wb.setOrderByWithDesc("createTime");
        if (params != null) {
            initPageParam(wb, params);
            wb.andFullLike("e.name", params.get("elderName"));
        }

        SelectBuilder builder = getSelectBuilder("r");
        builder.column("e.name as elderName")
                .join(Elder.class).alias("e").on("r.elderId = e.id").build();

        return queryPage(builder.getSql(), wb);
    }
}